<template>
  <div class="container">
    <router-link to="/">
      <div class="title">
        <img src="../assets/logo.png" alt="" />
        <h1>房屋租赁管理系统</h1>
      </div></router-link
    >
    <el-dropdown trigger="click" @command="handleCommand">
      <el-avatar
        shape="square"
        :size="50"
        :src="JSON.parse(this.$store.state.info).headImg"
        style="cursor: pointer"
      ></el-avatar>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="mine">个人中心</el-dropdown-item>
        <el-dropdown-item divided command="out">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: "Header",
  data() {
    return {};
  },
  methods: {
    //下拉菜单
    handleCommand(command) {
      // console.log(command);
      if (command == "mine" && this.$route.path != "/mine/index") {
        this.$router.push({ path: "/mine" });
      } else if (command == "out") {
        this.$store.dispatch("logout");
        this.$router.push({ path: "/login" });
      }
    },
  },
};
</script>

<style scoped lang="scss">
.container {
  width: 100vw;
  height: 80px;
  background-color: pink;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.12), 0 0 3px 0 rgba(0, 0, 0, 0.04);
  padding: 0 30px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .title {
    display: flex;
    align-items: center;
    color: #fff;
    img {
      margin-right: 10px;
    }
  }
}
</style>
